﻿package com.ease.flex.remoting
{
	import com.ease.util.RemoteService;
	import com.ease.util.ServiceUtil;
	import com.ease.util.events.MethodReturnEvent;
	import com.ease.framework.CallbackUtil;
	import com.obas.flex.common.event.SessionTimeoutEvent;
	import com.obas.flex.common.util.ClientErrorUtil;

	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.external.ExternalInterface;

	import mx.managers.BrowserManager;
	import com.obas.access.business.service.AaaCustomerAccessService;
	import com.obas.access.business.service.AaaOnlineAccessService;
	import com.obas.access.business.service.CircuitAccessService;
	import com.obas.access.business.service.CircuitAssociationAccessService;
	import com.obas.access.business.service.CustomerAccessService;
	import com.obas.access.business.service.CustomerNetworkServingAccessService;
	import com.obas.access.business.service.DeviceAccessService;
	import com.obas.access.business.service.PortAccessService;
	import com.obas.access.business.service.SlotAccessService;
	import com.obas.access.business.service.VlanAccessService;
	import com.obas.access.mature.service.BusinessApplicationAccessService;
	import com.obas.access.mature.service.BusinessServingAccessService;
	import com.obas.access.mature.service.NetworkBusinessAccessService;
	import com.obas.access.mature.service.NetworkServingAccessService;
	import com.obas.access.metadata.service.IndicatorTypeAccessService;
	import com.obas.business.aaa.service.AaaMinuteAggragationService;
	import com.obas.business.aaa.service.AaaMinuteAnalysisService;
	import com.obas.business.analogy.service.AnalogyManagementService;
	import com.obas.business.analogy.service.KpiAccumulateAnalogyProcessService;
	import com.obas.business.analogy.service.KpiBaseAnalogyProcessService;
	import com.obas.business.analogy.service.KpiStandardAnalogyProcessService;
	import com.obas.business.analogy.service.KqiAccumulateAnalogyProcessService;
	import com.obas.business.analogy.service.KqiBaseAnalogyProcessService;
	import com.obas.business.analogy.service.KqiStandardAnalogyProcessService;
	import com.obas.business.analogy.service.RawAnalogyProcessService;
	import com.obas.business.element.service.ElementMacAddressProcessService;
	import com.obas.business.element.service.NetworkTopologyManagementService;

	public class ServiceManagerComObasNetworkFlexRemoting {

		private static var _instance:ServiceManagerComObasNetworkFlexRemoting = null;

		public function ServiceManagerComObasNetworkFlexRemoting(singleton:SingletonClass) {
			var contextPath:String = ExternalInterface.call("BrowserHistory.getURL");
			RemoteService.defaultChannelUri = ServiceUtil.getDefaultChannelUri(contextPath);
		}

		public static function onOperationReturn(eventDispatcher:EventDispatcher, event:MethodReturnEvent):void {
	    	//var response:Event = null;
			//response = CallbackUtil.createResponseFromRequest(event.callContext, event.result, event.error);
			//eventDispatcher.dispatchEvent(response);
			
			var response:Event = null;
         	//Session timeout
         	if( null != event.error && ClientErrorUtil.getErrorType(event.error) == ClientErrorUtil.AUTHENTICATION_ERROR) {
            	var sessionTimeoutEvent:SessionTimeoutEvent = new SessionTimeoutEvent(SessionTimeoutEvent.SESSION_TIMEOUT);
            	eventDispatcher.dispatchEvent(sessionTimeoutEvent);
            	response = CallbackUtil.createResponseFromRequest(event.callContext, null, null);
         	} else {
            	response = CallbackUtil.createResponseFromRequest(event.callContext, event.result, event.error);
         	}
         	eventDispatcher.dispatchEvent(response);
		}

	    public static function getInstance():ServiceManagerComObasNetworkFlexRemoting {
	        if (_instance == null) {
				_instance = new ServiceManagerComObasNetworkFlexRemoting(new SingletonClass());
	        }

	        return _instance;
	    }
		private var _aaaCustomerAccessService:AaaCustomerAccessService = null;

		public static function getAaaCustomerAccessService():AaaCustomerAccessService {
			if (getInstance()._aaaCustomerAccessService == null) {
				getInstance()._aaaCustomerAccessService = new AaaCustomerAccessService();
			}
			return getInstance()._aaaCustomerAccessService;
		}

		public function set enabledAaaCustomerAccessService(value:Boolean):void {
			if (getInstance()._aaaCustomerAccessService) {
				getInstance()._aaaCustomerAccessService.enabled = value;
			}
		}
		private var _aaaOnlineAccessService:AaaOnlineAccessService = null;

		public static function getAaaOnlineAccessService():AaaOnlineAccessService {
			if (getInstance()._aaaOnlineAccessService == null) {
				getInstance()._aaaOnlineAccessService = new AaaOnlineAccessService();
			}
			return getInstance()._aaaOnlineAccessService;
		}

		public function set enabledAaaOnlineAccessService(value:Boolean):void {
			if (getInstance()._aaaOnlineAccessService) {
				getInstance()._aaaOnlineAccessService.enabled = value;
			}
		}
		private var _circuitAccessService:CircuitAccessService = null;

		public static function getCircuitAccessService():CircuitAccessService {
			if (getInstance()._circuitAccessService == null) {
				getInstance()._circuitAccessService = new CircuitAccessService();
			}
			return getInstance()._circuitAccessService;
		}

		public function set enabledCircuitAccessService(value:Boolean):void {
			if (getInstance()._circuitAccessService) {
				getInstance()._circuitAccessService.enabled = value;
			}
		}
		private var _circuitAssociationAccessService:CircuitAssociationAccessService = null;

		public static function getCircuitAssociationAccessService():CircuitAssociationAccessService {
			if (getInstance()._circuitAssociationAccessService == null) {
				getInstance()._circuitAssociationAccessService = new CircuitAssociationAccessService();
			}
			return getInstance()._circuitAssociationAccessService;
		}

		public function set enabledCircuitAssociationAccessService(value:Boolean):void {
			if (getInstance()._circuitAssociationAccessService) {
				getInstance()._circuitAssociationAccessService.enabled = value;
			}
		}
		private var _customerAccessService:CustomerAccessService = null;

		public static function getCustomerAccessService():CustomerAccessService {
			if (getInstance()._customerAccessService == null) {
				getInstance()._customerAccessService = new CustomerAccessService();
			}
			return getInstance()._customerAccessService;
		}

		public function set enabledCustomerAccessService(value:Boolean):void {
			if (getInstance()._customerAccessService) {
				getInstance()._customerAccessService.enabled = value;
			}
		}
		private var _customerNetworkServingAccessService:CustomerNetworkServingAccessService = null;

		public static function getCustomerNetworkServingAccessService():CustomerNetworkServingAccessService {
			if (getInstance()._customerNetworkServingAccessService == null) {
				getInstance()._customerNetworkServingAccessService = new CustomerNetworkServingAccessService();
			}
			return getInstance()._customerNetworkServingAccessService;
		}

		public function set enabledCustomerNetworkServingAccessService(value:Boolean):void {
			if (getInstance()._customerNetworkServingAccessService) {
				getInstance()._customerNetworkServingAccessService.enabled = value;
			}
		}
		private var _deviceAccessService:DeviceAccessService = null;

		public static function getDeviceAccessService():DeviceAccessService {
			if (getInstance()._deviceAccessService == null) {
				getInstance()._deviceAccessService = new DeviceAccessService();
			}
			return getInstance()._deviceAccessService;
		}

		public function set enabledDeviceAccessService(value:Boolean):void {
			if (getInstance()._deviceAccessService) {
				getInstance()._deviceAccessService.enabled = value;
			}
		}
		private var _portAccessService:PortAccessService = null;

		public static function getPortAccessService():PortAccessService {
			if (getInstance()._portAccessService == null) {
				getInstance()._portAccessService = new PortAccessService();
			}
			return getInstance()._portAccessService;
		}

		public function set enabledPortAccessService(value:Boolean):void {
			if (getInstance()._portAccessService) {
				getInstance()._portAccessService.enabled = value;
			}
		}
		private var _slotAccessService:SlotAccessService = null;

		public static function getSlotAccessService():SlotAccessService {
			if (getInstance()._slotAccessService == null) {
				getInstance()._slotAccessService = new SlotAccessService();
			}
			return getInstance()._slotAccessService;
		}

		public function set enabledSlotAccessService(value:Boolean):void {
			if (getInstance()._slotAccessService) {
				getInstance()._slotAccessService.enabled = value;
			}
		}
		private var _vlanAccessService:VlanAccessService = null;

		public static function getVlanAccessService():VlanAccessService {
			if (getInstance()._vlanAccessService == null) {
				getInstance()._vlanAccessService = new VlanAccessService();
			}
			return getInstance()._vlanAccessService;
		}

		public function set enabledVlanAccessService(value:Boolean):void {
			if (getInstance()._vlanAccessService) {
				getInstance()._vlanAccessService.enabled = value;
			}
		}
		private var _businessApplicationAccessService:BusinessApplicationAccessService = null;

		public static function getBusinessApplicationAccessService():BusinessApplicationAccessService {
			if (getInstance()._businessApplicationAccessService == null) {
				getInstance()._businessApplicationAccessService = new BusinessApplicationAccessService();
			}
			return getInstance()._businessApplicationAccessService;
		}

		public function set enabledBusinessApplicationAccessService(value:Boolean):void {
			if (getInstance()._businessApplicationAccessService) {
				getInstance()._businessApplicationAccessService.enabled = value;
			}
		}
		private var _businessServingAccessService:BusinessServingAccessService = null;

		public static function getBusinessServingAccessService():BusinessServingAccessService {
			if (getInstance()._businessServingAccessService == null) {
				getInstance()._businessServingAccessService = new BusinessServingAccessService();
			}
			return getInstance()._businessServingAccessService;
		}

		public function set enabledBusinessServingAccessService(value:Boolean):void {
			if (getInstance()._businessServingAccessService) {
				getInstance()._businessServingAccessService.enabled = value;
			}
		}
		private var _networkBusinessAccessService:NetworkBusinessAccessService = null;

		public static function getNetworkBusinessAccessService():NetworkBusinessAccessService {
			if (getInstance()._networkBusinessAccessService == null) {
				getInstance()._networkBusinessAccessService = new NetworkBusinessAccessService();
			}
			return getInstance()._networkBusinessAccessService;
		}

		public function set enabledNetworkBusinessAccessService(value:Boolean):void {
			if (getInstance()._networkBusinessAccessService) {
				getInstance()._networkBusinessAccessService.enabled = value;
			}
		}
		private var _networkServingAccessService:NetworkServingAccessService = null;

		public static function getNetworkServingAccessService():NetworkServingAccessService {
			if (getInstance()._networkServingAccessService == null) {
				getInstance()._networkServingAccessService = new NetworkServingAccessService();
			}
			return getInstance()._networkServingAccessService;
		}

		public function set enabledNetworkServingAccessService(value:Boolean):void {
			if (getInstance()._networkServingAccessService) {
				getInstance()._networkServingAccessService.enabled = value;
			}
		}
		private var _indicatorTypeAccessService:IndicatorTypeAccessService = null;

		public static function getIndicatorTypeAccessService():IndicatorTypeAccessService {
			if (getInstance()._indicatorTypeAccessService == null) {
				getInstance()._indicatorTypeAccessService = new IndicatorTypeAccessService();
			}
			return getInstance()._indicatorTypeAccessService;
		}

		public function set enabledIndicatorTypeAccessService(value:Boolean):void {
			if (getInstance()._indicatorTypeAccessService) {
				getInstance()._indicatorTypeAccessService.enabled = value;
			}
		}
		private var _aaaMinuteAggragationService:AaaMinuteAggragationService = null;

		public static function getAaaMinuteAggragationService():AaaMinuteAggragationService {
			if (getInstance()._aaaMinuteAggragationService == null) {
				getInstance()._aaaMinuteAggragationService = new AaaMinuteAggragationService();
			}
			return getInstance()._aaaMinuteAggragationService;
		}

		public function set enabledAaaMinuteAggragationService(value:Boolean):void {
			if (getInstance()._aaaMinuteAggragationService) {
				getInstance()._aaaMinuteAggragationService.enabled = value;
			}
		}
		private var _aaaMinuteAnalysisService:AaaMinuteAnalysisService = null;

		public static function getAaaMinuteAnalysisService():AaaMinuteAnalysisService {
			if (getInstance()._aaaMinuteAnalysisService == null) {
				getInstance()._aaaMinuteAnalysisService = new AaaMinuteAnalysisService();
			}
			return getInstance()._aaaMinuteAnalysisService;
		}

		public function set enabledAaaMinuteAnalysisService(value:Boolean):void {
			if (getInstance()._aaaMinuteAnalysisService) {
				getInstance()._aaaMinuteAnalysisService.enabled = value;
			}
		}
		private var _analogyManagementService:AnalogyManagementService = null;

		public static function getAnalogyManagementService():AnalogyManagementService {
			if (getInstance()._analogyManagementService == null) {
				getInstance()._analogyManagementService = new AnalogyManagementService();
			}
			return getInstance()._analogyManagementService;
		}

		public function set enabledAnalogyManagementService(value:Boolean):void {
			if (getInstance()._analogyManagementService) {
				getInstance()._analogyManagementService.enabled = value;
			}
		}
		private var _kpiAccumulateAnalogyProcessService:KpiAccumulateAnalogyProcessService = null;

		public static function getKpiAccumulateAnalogyProcessService():KpiAccumulateAnalogyProcessService {
			if (getInstance()._kpiAccumulateAnalogyProcessService == null) {
				getInstance()._kpiAccumulateAnalogyProcessService = new KpiAccumulateAnalogyProcessService();
			}
			return getInstance()._kpiAccumulateAnalogyProcessService;
		}

		public function set enabledKpiAccumulateAnalogyProcessService(value:Boolean):void {
			if (getInstance()._kpiAccumulateAnalogyProcessService) {
				getInstance()._kpiAccumulateAnalogyProcessService.enabled = value;
			}
		}
		private var _kpiBaseAnalogyProcessService:KpiBaseAnalogyProcessService = null;

		public static function getKpiBaseAnalogyProcessService():KpiBaseAnalogyProcessService {
			if (getInstance()._kpiBaseAnalogyProcessService == null) {
				getInstance()._kpiBaseAnalogyProcessService = new KpiBaseAnalogyProcessService();
			}
			return getInstance()._kpiBaseAnalogyProcessService;
		}

		public function set enabledKpiBaseAnalogyProcessService(value:Boolean):void {
			if (getInstance()._kpiBaseAnalogyProcessService) {
				getInstance()._kpiBaseAnalogyProcessService.enabled = value;
			}
		}
		private var _kpiStandardAnalogyProcessService:KpiStandardAnalogyProcessService = null;

		public static function getKpiStandardAnalogyProcessService():KpiStandardAnalogyProcessService {
			if (getInstance()._kpiStandardAnalogyProcessService == null) {
				getInstance()._kpiStandardAnalogyProcessService = new KpiStandardAnalogyProcessService();
			}
			return getInstance()._kpiStandardAnalogyProcessService;
		}

		public function set enabledKpiStandardAnalogyProcessService(value:Boolean):void {
			if (getInstance()._kpiStandardAnalogyProcessService) {
				getInstance()._kpiStandardAnalogyProcessService.enabled = value;
			}
		}
		private var _kqiAccumulateAnalogyProcessService:KqiAccumulateAnalogyProcessService = null;

		public static function getKqiAccumulateAnalogyProcessService():KqiAccumulateAnalogyProcessService {
			if (getInstance()._kqiAccumulateAnalogyProcessService == null) {
				getInstance()._kqiAccumulateAnalogyProcessService = new KqiAccumulateAnalogyProcessService();
			}
			return getInstance()._kqiAccumulateAnalogyProcessService;
		}

		public function set enabledKqiAccumulateAnalogyProcessService(value:Boolean):void {
			if (getInstance()._kqiAccumulateAnalogyProcessService) {
				getInstance()._kqiAccumulateAnalogyProcessService.enabled = value;
			}
		}
		private var _kqiBaseAnalogyProcessService:KqiBaseAnalogyProcessService = null;

		public static function getKqiBaseAnalogyProcessService():KqiBaseAnalogyProcessService {
			if (getInstance()._kqiBaseAnalogyProcessService == null) {
				getInstance()._kqiBaseAnalogyProcessService = new KqiBaseAnalogyProcessService();
			}
			return getInstance()._kqiBaseAnalogyProcessService;
		}

		public function set enabledKqiBaseAnalogyProcessService(value:Boolean):void {
			if (getInstance()._kqiBaseAnalogyProcessService) {
				getInstance()._kqiBaseAnalogyProcessService.enabled = value;
			}
		}
		private var _kqiStandardAnalogyProcessService:KqiStandardAnalogyProcessService = null;

		public static function getKqiStandardAnalogyProcessService():KqiStandardAnalogyProcessService {
			if (getInstance()._kqiStandardAnalogyProcessService == null) {
				getInstance()._kqiStandardAnalogyProcessService = new KqiStandardAnalogyProcessService();
			}
			return getInstance()._kqiStandardAnalogyProcessService;
		}

		public function set enabledKqiStandardAnalogyProcessService(value:Boolean):void {
			if (getInstance()._kqiStandardAnalogyProcessService) {
				getInstance()._kqiStandardAnalogyProcessService.enabled = value;
			}
		}
		private var _rawAnalogyProcessService:RawAnalogyProcessService = null;

		public static function getRawAnalogyProcessService():RawAnalogyProcessService {
			if (getInstance()._rawAnalogyProcessService == null) {
				getInstance()._rawAnalogyProcessService = new RawAnalogyProcessService();
			}
			return getInstance()._rawAnalogyProcessService;
		}

		public function set enabledRawAnalogyProcessService(value:Boolean):void {
			if (getInstance()._rawAnalogyProcessService) {
				getInstance()._rawAnalogyProcessService.enabled = value;
			}
		}
		private var _elementMacAddressProcessService:ElementMacAddressProcessService = null;

		public static function getElementMacAddressProcessService():ElementMacAddressProcessService {
			if (getInstance()._elementMacAddressProcessService == null) {
				getInstance()._elementMacAddressProcessService = new ElementMacAddressProcessService();
			}
			return getInstance()._elementMacAddressProcessService;
		}

		public function set enabledElementMacAddressProcessService(value:Boolean):void {
			if (getInstance()._elementMacAddressProcessService) {
				getInstance()._elementMacAddressProcessService.enabled = value;
			}
		}
		private var _networkTopologyManagementService:NetworkTopologyManagementService = null;

		public static function getNetworkTopologyManagementService():NetworkTopologyManagementService {
			if (getInstance()._networkTopologyManagementService == null) {
				getInstance()._networkTopologyManagementService = new NetworkTopologyManagementService();
			}
			return getInstance()._networkTopologyManagementService;
		}

		public function set enabledNetworkTopologyManagementService(value:Boolean):void {
			if (getInstance()._networkTopologyManagementService) {
				getInstance()._networkTopologyManagementService.enabled = value;
			}
		}

	}
}
class SingletonClass{}
